<?php
	class FlinkModel extends Model {
		function __construct(){
			parent:: __construct();
			$this->tabName = TAB_PREFIX."flink";
			$this->fieldList=array("id","webName", "url", "logo", "email","dtime", "msg", "list", "ord");
		
		}
	
		function validateForm(){
			$result=true;
			if(!Validate::required($_POST['webName'])) {
				$this->messList[] = "网站名称不能为空.";
				$result=false;
			}
			if(!Validate::required($_POST['url'])) {
				$this->messList[] = "网站URL不能为空.";
				$result=false;
			}
			if(!Validate::match($_POST['url'], "/http\:\/\//")) {
				$this->messList[] = "不是正确的URL格式.";
				$result=false;
			}
			if(!Validate::required($_POST['logo'])) {
				$this->messList[] = "网站LOGO图片地址不能为空.";
				$result=false;
			}
			if(!Validate::required($_POST['email'])) {
				$this->messList[] = "网站管理员的电子邮箱地址不能为空.";
				$result=false;
			}
			if(!Validate::match($_POST['email'], "/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/")) {
				$this->messList[] = "网站管理员邮箱不是正确的电子邮件格式.";
				$result=false;
			}
			if(Validate::match($_POST['webName'], "|[\\\/\'\"]|")) {
				$this->messList[] = "网站名称含有非法字符, 不能包含\\ / ' \"等字符.";
				$result=false;
			}
		
			if(!Validate::checkLength($_POST['msg'], 300)) {
				$this->messList[] = "网站描述不能超过100个汉字.";
				$result=false;
			}
			return  $result;
		}


		function modOrder($ords, $ids){
			$stmt=$this->mysqli->prepare("UPDATE {$this->tabName} SET ord=? WHERE id=?");
			$stmt->bind_param('ii', $ord, $id);
			$aff=0;
			for($i=0; $i<count($ords); $i++){
				$id=$ids[$i];
				$ord=$ords[$i];
				$stmt->execute();
				$aff++;
			}
			if($aff>0){
				return true;
			}else{
				return false;
			}
		}


	}
